class Search < Struct.new(:user, :p)
  def start_date
    lead_zero(p["start_date(1i)"].to_i, p["start_date(2i)"].to_i, p["start_date(3i)"].to_i)
  end
  
  def end_date
    lead_zero(p["end_date(1i)"].to_i, p["end_date(2i)"].to_i, p["end_date(3i)"].to_i)
  end
  
  def with_scoping(klass, options = {})
    klass.send(:with_scope, :find => options) { yield }
  end
  
  private
  
  def lead_zero(y, m, d)
    m = "0" + m.to_s if m < 10
    d = "0" + d.to_s if d < 10
    [y, m, d].join("-")
  end
end